#!/bin/sh

dockerpids=$(docker ps -f name="docker_zk*" | awk '{print $1}' )
for dockerpid in $dockerpids
do 
  echo "被删除的容器 $dockerpid"
  docker stop $dockerpid
  docker rm $dockerpid
done  
echo "容器已删除完毕！"

ipids=$(docker images | grep "none*" | awk '{print $3}')
for imagesid in $ipids
do
  echo "被删除的image $imagesid"
  docker rmi $imagesid
done  

docker ps -a |grep "docker_zk*"|awk '{print $1}'|xargs docker stop
docker ps -a |grep "docker_zk*"|awk '{print $1}'|xargs docker rm
docker image ls|grep none|awk '{print $3}'|xargs docker rmi

echo "旧的docker docker-demo 容器和镜像已删除"

rm -rf docker-zk-run.yml
echo "删除docker-zk-run配置文件"

docker-compose -f docker-zk-base.yml -f docker-zk.yml config > docker-zk-run.yml
echo "docker-zk-run配置文件合并完成"

docker-compose -f docker-zk-run.yml up -d

echo "容器启动完成,结束."
